import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/reg',
    component: () => import('@/views/reg/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: () => import('@/layout'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' },
      },
    ]
  },

  // {
  //   path: '/',
  //   component: () => import('@/layout'),
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'log',
  //       name: 'log',
  //       component: () => import('@/views/log'),
  //       meta: { title: '日志管理', icon: 'link' }
  //     },
  //   ]
  // },

  {
    path: '/',
    component: () => import('@/layout'),
    redirect: '/dashboard',
    children: [
      {
        path: 'personInfo',
        name: 'personInfo',
        component: () => import('@/views/personInfo/index'),
        meta: { title: '个人中心', icon: 'dashboard' },
      }
    ]
  },

  // {
  //   path: '/',
  //   component: () => import('@/layout'),
  //   redirect: '/collect',
  //   children: [
  //     {
  //       path: 'collect',
  //       name: 'collect',
  //       component: () => import('@/views/personInfo/index'),
  //       meta: { title: '我的收藏', icon: 'dashboard' },
  //     }
  //   ]
  // },

  {
    path: '/',
    component: () => import('@/layout'),
    redirect: '/orderlist',
    children: [
      {
        path: 'orderlist',
        name: 'orderlist',
        component: () => import('@/views/order/index'),
        meta: { title: '我的订单', icon: 'dashboard' },
      }
    ]
  },


  // {
  //   path: '/sys',
  //   component: () => import('@/layout'),
  //   name: 'sys',
  //   meta: { title: '系统管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'user',
  //       name: 'user',
  //       component: () => import('@/views/sys/user.vue'),
  //       meta: { title: '用户管理', icon: 'table' }
  //     },
  //     {
  //       path: 'role',
  //       name: 'role',
  //       component: () => import('@/views/sys/role.vue'),
  //       meta: { title: '角色管理', icon: 'table' }
  //     },
  //     {
  //       path: 'permission',
  //       name: 'permission',
  //       component: () => import('@/views/sys/permission.vue'),
  //       meta: { title: '权限管理', icon: 'table' }
  //     }
  //   ]
  // },
  // {
  //   path: '/service',
  //   component: () => import('@/layout'),
  //   name: 'service',
  //   meta: {
  //     title: '业务管理',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'service1',
  //       component: () => import('@/views/service/service1.vue'), // Parent router-view
  //       name: 'service1',
  //       meta: { title: '菜单1' },
  //     },
  //     {
  //       path: 'service2',
  //       component: () => import('@/views/service/service2.vue'),
  //       name: 'service2',
  //       meta: { title: '菜单2' }
  //     }
  //   ]
  // },

  // { path: '*', redirect: '/404', hidden: true },

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
